package com.cfpl.admin_vegetable_service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cfpl.admin_service.VO.PageQueryCondition;
import com.cfpl.admin_vegetable_service.VO.SearchResult;
import com.cfpl.admin_vegetable_service.service.WarehouseService;
import com.cfpl.project_common.pojo.Warehouse;
import com.cfpl.project_common.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: wrp
 * @Date: 2023/11/5 - 21:39
 * @Description: com.cfpl.admin_vegetable_service.controller
 * @version: 1.0
 */
@RestController
@Slf4j
@Api(tags = "仓库管理相关接口")
@RequestMapping("/warehouse")
public class WarehouseController {

    @Autowired
    private WarehouseService warehouseService;

    /**
     * 功能描述：分页查询所有仓库数据
     * @param current
     * @param pageSize
     * @param condition
     * @return
     */
    @ApiOperation("分页查询仓库数据")
    @GetMapping("/pageQueryWarehouse")
    public BaseResult<PageQueryCondition> queryAll(int current,int pageSize,String condition) {
        Page<Warehouse> page = warehouseService.queryPage(current,pageSize,condition);
        PageQueryCondition queryCondition = new PageQueryCondition(page,condition);
        return BaseResult.ok(queryCondition);

    }

    /**
     * 功能描述：添加仓库数据
     * @param warehouse
     * @return
     */
    @ApiOperation("新增仓库数据")
    @PostMapping("/addWarehouse")
    public BaseResult addWarehouse(@RequestBody Warehouse warehouse) {
        warehouseService.addWarehouse(warehouse);
        return BaseResult.ok();
    }

    @ApiOperation("查询追溯信息")
    @GetMapping("/queryTraceabilityInfo")
    public BaseResult<SearchResult> queryTraceabilityInfo(String identifyCode){
        SearchResult searchResult = warehouseService.queryTraceabilityInfo(identifyCode);
        return BaseResult.ok(searchResult);
    }

}
